package com.study5.mybatis.dayima.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.yoloho.redis.RedisServiceImpl;
import com.yoloho.redis.api.RedisService;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xuly
 * @title: DruidConfig
 * @projectName spring-boot
 * @description: TODO
 * @date 2019-07-2415:55
 **/
@Configuration
public class DruidConfig {

    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource druidDataSource() {
        return new DruidDataSource();
    }

    @Bean
    @Resource
    public SqlSessionFactoryBean mybatisSessionFactory(DataSource druidDataSource) {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(druidDataSource);
        return factoryBean;
    }

    @Bean
    @Resource
    public RedisService redisService(StringRedisTemplate stringRedisTemplate) {
        RedisService redisService = new RedisServiceImpl();
        ((RedisServiceImpl) redisService).setRedisTemplate(stringRedisTemplate);
        return redisService;
    }

}
